package com.abe.bathsystem.widget.dialog;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;

import com.abe.bathsystem.base.ManagerLocalData;
import com.abe.bathsystem.widget.OnOperateListener;
import com.abe.libcore.utils.normal.ToastUtils;

import net.yet.campusdev.R;

public class SupportLimitBathDialog extends BaseDialog {

    private DialogContract.OnSupportLimitBathListener listener;

    public SupportLimitBathDialog(@NonNull Context context) {
        super(context);
    }

    public SupportLimitBathDialog(@NonNull Context context, OnOperateListener operateListener) {
        super(context, operateListener);
    }

    public void setListener(DialogContract.OnSupportLimitBathListener listener) {
        this.listener = listener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.item_view_v3_support_common);
        ((TextView) findViewById(R.id.item_edit_value)).setText(R.string.support_limit_bath);
        final RadioButton yes = findViewById(R.id.item_radio_y);
        final RadioButton no = findViewById(R.id.item_radio_n);
        boolean isSupport = ManagerLocalData.isSupportLimitBath();
        yes.setChecked(isSupport);
        no.setChecked(!isSupport);
        yes.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                no.setChecked(!b);
            }
        });
        no.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                yes.setChecked(!b);
            }
        });
        ((Button) findViewById(R.id.item_btn_setting)).setText(R.string.setting);
        findViewById(R.id.item_btn_setting).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onSupportLimitBath(yes.isChecked());
                } else {
                    ToastUtils.show("请绑定回调监听");
                }
                dismiss();
            }
        });
    }
}
